﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using TriviaDal;
using TriviaModel;

namespace TriviaWCF
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class GameService : IGameService
    {
        TriviaDalClass dal = new TriviaDalClass();
        /// <summary>
        /// return question by difficulty and type
        /// </summary>
        /// <param name="Difficulty"></param>
        /// <param name="qtype"></param>
        /// <returns></returns>


        public List<QuestionCalss> GetQusetions(string Difficulty, string qtype)
        {
            var list = dal.GetQusetions(Difficulty, qtype);
            return list;
        }

        public List<AnswerCalss> GetAnsweres(List<int> questionsId)
        {
            //return dal.GetAnsweres(questionsId);\
            return null;
        }

        public bool InsertUser(string name, string password)
        {
            return dal.InsertUser(name, password);
        }

        public List<string> GetTopics()
        {
            return dal.GetTopics();
        }

        public List<string> GetDificulties()
        {
            return dal.GetDificulties();
        }

        public bool IsTheAnswerRight(int answerId, int questionId)
        {
            return dal.IsTheAnswerRight(answerId, questionId);
        }

        public List<UserClass> ReturnUsers()
        {
            return dal.ReturnUsers();
        }

        public int CalcAndGetScore(List<int> timeScore, string userNam, string password)
        {
            int score = 0;
            if (timeScore.Count > 0)
            {
                for (int i = 0; i < timeScore.Count; i++)
                {
                    if (timeScore[i] < 30)
                        score += 20;
                    else
                        score += 10;
                }
            }
            dal.CalcAndGetScore(score, userNam, password);
            return (int)score;
        }


        public bool AddTopic(string topic)
        {
            return dal.AddTopic(topic);
        }

        public bool AddDificulty(string difficulty)
        {
            return dal.AddDifficulty(difficulty);
        }


        public int AddQuestion(QuestionCalss question)
        {
            return dal.AddQuestion(question);
        }

        public void AddAnswers(List<AnswerCalss> answers)
        {
            dal.AddAnswers(answers);
        }

        public int GetDifficultyId(string difficultyLevel)
        {
            return dal.GetDifficultyId(difficultyLevel);
        }

        public int GetTypeId(string Typestring)
        {
            return dal.GetTypeId(Typestring);
        }
    }
}
